package com.itheima.api.treemap.demo04;

import java.util.TreeMap;

public class TreeMapDemo01 {

    public static void main(String[] args) {

        String s = "aababcabcdabcde";

        char[] chars = s.toCharArray();

        TreeMap<Character, Integer> treeMap = new TreeMap<Character, Integer>();

        for(int i = 0; i < chars.length; i++) {
            char c = chars[i];
            Integer integer = treeMap.get(c);
            if(integer == null) {
                treeMap.put(c, 1);
            }else {
                integer = integer + 1;
                treeMap.put(c, integer);
            }
        }

        StringBuilder sb = new StringBuilder();

        treeMap.forEach((key, value) -> {
            sb.append(key + "(" + value + ")");
        });

        String string = sb.toString();

        System.out.println(string);

    }

}
